/*
 * @Date: 2023-08-04 14:21:58
 * @LastEditors: lyx
 * @LastEditTime: 2023-11-14 15:35:19
 * @FilePath: \sup-mimi-program-server\src\interceptors\transform\transform.interceptor.ts
 * @Description:
 */
import {
  Injectable,
  NestInterceptor,
  CallHandler,
  ExecutionContext,
} from '@nestjs/common';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
interface Response<T> {
  content: T;
}
@Injectable()
export class TransformInterceptor<T>
  implements NestInterceptor<T, Response<T>>
{
  intercept(
    context: ExecutionContext,
    next: CallHandler<T>,
  ): Observable<Response<T>> {
    return next.handle().pipe(
      map((data) => {
        return {
          isSuccess: true,
          content: data,
          code: '00000',
          status: true,
          msg: '请求成功',
        };
      }),
    );
  }
}
